package com.sdry.good.goodWarehouse.controller;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.sdry.untils.ResponseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import java.io.PrintWriter;
import java.util.Date;
import com.sdry.good.goodWarehouse.entity.GoodContainerStare;
import com.sdry.good.goodWarehouse.service.GoodContainerStareService;
import com.sdry.good.goodWarehouse.mapper.GoodContainerStareMapper;
/**
 *
 *@ClassName: GoodContainerStareController
 *@Description: 成品容器绑定表
 *@Author tdd
 *@Date 2020-03-25 16:04:53
 *@version 1.0
*/
@Controller
@RequestMapping("/goodContainerStare")
public class GoodContainerStareController{
	@Resource GoodContainerStareService goodContainerStareService;
	//声明一个Logger
	private final static Logger logger = LoggerFactory.getLogger(GoodContainerStareController.class);
	/** 
	 * 进入页面
	 * @param model
	 * @return 页面路径
	*/
	@RequestMapping("/goodInventory")
	public String pageGoodContainerStare (Model model) {
		return "/td/goodWarehouse/goodInventory";
	}

	/**
	 * 进入成品容器绑定未入库表
	 * @param model
	 * @return 页面路径
	*/
	@RequestMapping("/goodContainerStare")
	public String goodContainerStare (Model model) {
		return "/td/goodWarehouse/goodContainerStare";
	}

	/** 
	 * 根据条件查询所有
	 * @param param 实体条件
	 * @return 实体集合
	*/
	@RequestMapping("/queryAllByMution")
	@ResponseBody
	public List<GoodContainerStare> queryAllByMution(GoodContainerStare param) {
		logger.info("根据条件查询所有条件"+JSONArray.fromObject(param));
		List<GoodContainerStare> list = goodContainerStareService.queryAllByMution(param);
		logger.info("根据条件查询所有返回内容"+JSONArray.fromObject(list));
		return list;
	}
	/** 
	 * 根据条件分页查询
	 * @param param 实体条件
	 * @param response
	*/
	@RequestMapping("/list")
	public void list(GoodContainerStare param,HttpServletResponse response){
		logger.info("根据条件分页查询条件"+JSONArray.fromObject(param));
		/*
		 * 条件分页查询内容
		 */
		List<GoodContainerStare> list = goodContainerStareService.findPageByMution(param);
		logger.info("根据条件分页查询条件返回内容"+JSONArray.fromObject(list));
		/*
		 * 条件查询总条数
		 */
		Integer total = goodContainerStareService.selectCountByMution(param);
		logger.info("条件查询总条数返回条数"+total);
		/*
		 * 转为json数据传至页面
		 */
		//创建result
		JSONObject jsonObject = new JSONObject();
		//添加入jsonObject
		jsonObject.put("code", 0);
		jsonObject.put("rows", list);
		jsonObject.put("total", total);
		try {
			ResponseUtil.write(response, jsonObject);
		} catch (Exception e) {
			logger.info("根据条件分页查询返回数据失败");
			e.printStackTrace();
		}
	}
	/**
	 * 根据条件分页查询
	 * @param param 实体条件
	 * @param response
	*/
	@RequestMapping("/listInventory")
	public void listInventory(GoodContainerStare param,HttpServletResponse response){
		logger.info("根据条件分页查询条件"+JSONArray.fromObject(param));
		/*
		 * 条件分页查询内容
		 */
		List<GoodContainerStare> list = goodContainerStareService.findInventoryPageByMution(param);
		logger.info("根据条件分页查询条件返回内容"+JSONArray.fromObject(list));
		/*
		 * 条件查询总条数
		 */
		Integer total = goodContainerStareService.selectInventoryCountByMution(param);
		logger.info("条件查询总条数返回条数"+total);
		/*
		 * 转为json数据传至页面
		 */
		//创建result
		JSONObject jsonObject = new JSONObject();
		//添加入jsonObject
		jsonObject.put("code", 0);
		jsonObject.put("rows", list);
		jsonObject.put("total", total);
		try {
			ResponseUtil.write(response, jsonObject);
		} catch (Exception e) {
			logger.info("根据条件分页查询返回数据失败");
			e.printStackTrace();
		}
	}
}
